package org.csu.ssm_backend.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.csu.ssm_backend.domain.Order;
import org.csu.ssm_backend.persistence.OrderMapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@MapperScan("org.csu.ssm_backend.persistence")
public class OrderService {
    @Resource
    private OrderMapper orderMapper;

    OrderService(){
    }

    public List<Order> getOrderList(String userid){
        QueryWrapper<Order> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("userid",userid);
        return orderMapper.selectList(queryWrapper);
    }

    public Order getOrder(String userid,String orderid){
        QueryWrapper<Order> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("userid",userid).eq("orderid",orderid);
        return orderMapper.selectOne(queryWrapper);
    }

    public void deleteOrder(String userid,String orderid){
        QueryWrapper<Order> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("userid",userid).eq("orderid",orderid);
        orderMapper.delete(queryWrapper);
    }
}
